package handler;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

import dao.CompactDiscDao;

public class LoadDeleteDiscHandler implements ISetParamHandler{	
	private static final Logger LOGGER = Logger.getLogger(LoadDeleteDiscHandler.class);

	private List<Long> idCDs = new ArrayList<Long>();
	
	@Override
	public String setRequest(HttpServletRequest request) {
		String ids[] = request.getParameter("ids").split(",");
		for(String id : ids) {
			idCDs.add(Long.parseLong(id));
		}
		return "OK";
	}

	public String process() {
		String result = null;
    	try {
    		result = CompactDiscDao.deleteCompactDiscs(idCDs);
		} catch (Exception e) {
			String error = "Error on deleting cds " + e.getMessage();
			LOGGER.error(error);
			return error;
		};
		return result;
	}
	
}
